﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WINADM.Data;
using System.Data.Objects;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using Microsoft.Research.DynamicDataDisplay.PointMarkers;
using Microsoft.Research.DynamicDataDisplay;
namespace WPFTester
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WINADMEntities dataStore = new WINADMEntities();
            Computer computer = dataStore.Computers.Single(x => x.ComputerName == System.Environment.MachineName);
            List<DateTime> dates = new List<DateTime>();
            List<Int32> vals = new List<int>();
            CPUUsage[] cpuusages = computer.CPUUsages.Where(x => x.Time > System.DateTime.Now.AddMinutes(-1)).ToArray<CPUUsage>();

            //foreach (CPUUsage cpuusage in computer.CPUUsages)
            //{
            //    dates.Add(cpuusage.Time);
            //    vals.Add(cpuusage.Value);
            //}

            var datesDataSource = new EnumerableDataSource<CPUUsage>(cpuusages);
            datesDataSource.SetXMapping(x => dateAxis.ConvertToDouble(x.Time));

            var cpuUsageDataSource = new EnumerableDataSource<CPUUsage>(cpuusages);
            cpuUsageDataSource.SetYMapping(y => y.Value);

            CompositeDataSource compositeDataSource1 = new CompositeDataSource(datesDataSource, cpuUsageDataSource);
            plotter.AddLineGraph(compositeDataSource1,
        new Pen(Brushes.Red, 2),
          new PenDescription("CPU Usage"));
            plotter.Viewport.FitToView();
        }
    }
}
